#!/usr/bin/python
# coding:utf-8
import string, random, time
from src.utils.models import db


class Account(db.Model):
    """
    @tableName:pay_account
    """
    __tablename__ = 'pay_account'
    id = db.Column(db.String(30), primary_key=True, default=str(int(time.time() * 1000)) + ''.join(
        random.sample(string.ascii_letters + string.digits, 20)))
    pid = db.Column(db.String(30))
    code = db.Column(db.String(30))  # CNY001001001001001 1-3货币4-6分类码7-9 10-12 一二级码 13-15明细码
    name = db.Column(db.String(25), nullable=False)
    description = db.Column(db.String(25), nullable=False)
    currency_iso = db.Column(db.String(25), nullable=False, default='CNY')
    level = db.Column(db.Integer, nullable=False)
    direct = db.Column(db.Integer, nullable=False)  # -1 +1
    status = db.Column(db.Integer, nullable=False)  # '账务状态；1-正常；0-冻结；-1-销户',
    validity_period_start = db.Column(
        db.BigInteger, nullable=False, default=time.time() * 1000000)
    validity_period_end = db.Column(
        db.BigInteger, nullable=False, default=4102376399) # 2059年12月31日

    created_time = db.Column(db.BigInteger, nullable=False, default=int(time.time() * 1000))
    created_user_id = db.Column(
        db.Integer, db.ForeignKey('sys_user.id'))
    updated_time = db.Column(
        db.BigInteger, nullable=False, default=int(time.time() * 1000))
    updated_user_id = db.Column(
        db.Integer, db.ForeignKey('sys_user.id'))

    def __init__(self, content, state=None):
        self.content = content
        self.state = state

    def __repr__(self):
        return '<Account %r>' % self.name


class AccountBook(db.Model):
    """
    @tableName:pay_account_book
    """
    __tablename__ = 'pay_account_book'
    id = db.Column(db.String(30), primary_key=True, default='ACB' + ''.join(random.sample(
        string.ascii_letters + string.digits, 10)) + '.' + str(int(time.time() * 1000)))
    pid = db.Column(db.String(30))
    vocher_id = db.Column(db.String(30), primary_key=True, default='ACB' + ''.join(random.sample(
        string.ascii_letters + string.digits, 10)) + '.' + str(int(time.time() * 1000)))
    description = db.Column(db.String(100), nullable=False)
    account_id = db.Column(db.String(30), )
    currency_code = (db.String(30), db.ForeignKey('sys_currency.id'))
    dr = db.Column(db.Numeric(20, 4), nullable=False)  # Debits
    cr = db.Column(db.Numeric(20, 4), nullable=False)  # Credits
    value = db.Column(db.Numeric(20, 4), nullable=False)  # value
    status = db.Column(db.Integer, nullable=False)  # '账务状态；1-正常；0-无效',
    

    #
    created_time = db.Column(db.BigInteger, nullable=False, default=int(time.time() * 1000))
    created_user_id = db.Column(
        db.Integer, db.ForeignKey('sys_user.id'))
    updated_time = db.Column(
        db.BigInteger, nullable=False, default=int(time.time() * 1000))
    updated_user_id = db.Column(
        db.Integer, db.ForeignKey('sys_user.id'))

    def __init__(self, content, state=None):
        self.content = content
        self.state = state

    def __repr__(self):
        return '<Account Book %r>' % self.contain
